//一级路由组件引入
import Login from '@/pages/login';
import Register from '@/pages/register';
import Detail from '@/pages/detail';
import AddCartSuccess from '@/pages/addCartSuccess'
import ShopCart from '@/pages/shopCart'
import Trade from '@/pages/trade'
import Pay from '@/pages/pay'
import PaySuccess from '@/pages/paySuccess'
import Center from '@/pages/center'

//二级路由
import MyOrder from '@/pages/center/myOrder';
import TeamOrder from '@/pages/center/teamOrder'
export default [
    {
        path: '/home',//地址URL单词都是小写的
        component:()=>import('@/pages/home'),
        //路由元信息:给当前路由,注入一些额外的信息
        meta: { show: true }
    }
    ,
    {
        //命名路由【很重要:params参数占位了，需要命名路由】
        name: 'search',
        //:keyword?,代表次params参数可以传递,也可以不传递
        //?理解:很向正则表达式的量词?，代表出现零次|一次！！！！
        path: '/search/:keyword?',
        component:()=>import('@/pages/search'),
        meta: { show: true },
        //讲解路由组件传递props三种写法
        //第一种写法:
        //布尔写法:代表给路由组件search传递props数据,传递的是params参数
        // props:true,

        //第二种写法:对象写法
        // props: {
        //     a: 1,
        //     b: 222,
        //     c: '哈哈'
        // }

        //第三种写法:函数写法，params|query参数注入给路由组件props
        //当有其他路由跳转到search路由的时候,props右侧箭头函数会立即执行一次,要给路由组件search注入props数据！！！[人家vue-router帮咱们调用的]
        props: (route) => ({ k: route.params.keyword, k1: 'xxxx' }),
        //route:其实就是当前路由对象，可以获取当前路由params|query参数!!!!
        //当前案例次路由没有传递query，如果有query参数，也可以当中props传递给路由组件！！！！
        //return回来的对象，注入给路由组件props====['k','k1']
        //上面写法是箭头函数简写方式，完整写法如下
        // props:(route)=>{
        //     return {k:route.params.keyword,k1:'xxxx'}
        // }
    }
    ,
    {
        path: '/login',
        component: Login,
        meta: { show: false }
    },
    {
        path: '/register',
        component: Register,
        meta: { show: false }
    },
    //重定向
    {
        path: '/',
        redirect: '/home'
    }
    , {
        path: '/detail/:skuId',
        component: Detail,
        meta: { show: true }
    },
    {
        path: '/addcartsuccess',
        component: AddCartSuccess,
        meta: {
            show: true
        }
    },
    {
        path: '/shopcart',
        component: ShopCart,
        meta: {
            show: true
        }
    },
    {
        path: '/trade',
        component: Trade,
        meta: {
            show: true
        },
        //路由独享守卫
        beforeEnter: (to, from, next) => {
            if (from.path == '/shopcart') {
                next();
            }else{
                //从哪来回哪去-->地址URL是正确的
                next(false);
            }
        }

    },
    {
        path: '/pay',
        component: Pay,
        meta: {
            show: true
        },
        //路由独享守卫
        beforeEnter: (to, from, next) => {
            if(from.path=='/trade'){
                next();
            }else{
                next(false)
            }
        }
    },
    {
        path: '/paysuccess',
        component: PaySuccess,
        meta: {
            show: true
        }

    },
    {
        path: '/center',
        component: Center,
        meta: {
            show: true
        },
        children: [
            {
                path: 'myorder',
                component: MyOrder
            },
            {
                path: 'teamorder',
                component: TeamOrder
            }
            ,
            {
                path: '/center',
                redirect: '/center/myorder'
            }
        ]
    }
]